package JUC_study.c_025;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TimeUnit;

public class T09_TransferQueue {
    public static void main(String[] args) throws InterruptedException {
        LinkedTransferQueue<String> strs = new LinkedTransferQueue<>();//传递的内容是有长度的，多个的

        new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
                System.out.println(strs.take());
                System.out.println(strs.take());
                System.out.println(strs.take());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    strs.transfer("bbb");
                    strs.transfer("ccc");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

        TimeUnit.SECONDS.sleep(1);
        strs.transfer("aaa");//装完后，阻塞等待其他线程取走后才继续执行，跟满不满没有关系

        //strs.put("aaa");//放完后当前线程就走了


		/*new Thread(() -> {
			try {
				System.out.println(strs.take());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}).start();*/


    }
}
